#!/usr/bin/env python
# -*- encoding: utf-8 -*-
'''
@File    :   response_code.py
@Time    :   2021/02/06 12:31:52
@Author  :   superjin
@Version :   1.0
'''

from typing import Union

from fastapi import status
from fastapi.responses import JSONResponse, Response
from fastapi.encoders import jsonable_encoder


def resp_200(*, data: Union[list, dict, str] = None, message: str = "Success") -> Response:
    return jsonable_encoder({'code':200,'resMsg':message,'data':data})

def resp_500(*, data: Union[list, dict, str] = None, message: str = "Internal Server Error") -> Response:
    return JSONResponse(
        #status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
        status_code=status.HTTP_200_OK,
        content=jsonable_encoder({
            'code': 500,
            'resMsg': message,
            'data': data,
        })
    )
    #return jsonable_encoder({'code':500,'resMsg':message,'data':data})



def resp_502(*, data: Union[list, dict, str] = None, message: str = "Internal Server Error") -> Response:
    return JSONResponse(
        status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
        #status_code=status.HTTP_200_OK,
        content=jsonable_encoder({
            'code': 502,
            'resMsg': message,
            'data': data,
        })
    )
